//
//  AppDelegate.m
//  lg_zhinengbeikao_english
//
//  Created by 朱凯 on 2018/12/10.
//  Copyright © 2018年 zhukai. All rights reserved.
//

#import "AppDelegate.h"

#import "KZTabBarController.h"
#import "KZGuideViewController.h"

#import "AppDelegate+KZAppDelegateConfig.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    NSLog(@"1");
//    KZTabBarController *vc = [KZTabBarController new];
//    self.window.rootViewController = vc;
    
    // 初始化配置
    [self addScrollAdaption];
    [self addKouYuSDK];
    [self addAFNetListening];
    [self addKeyboardManager];
    
    [self enterSystem];
    
    
    return YES;
}

#pragma mark - 进入系统
- (void)enterApp {
    
    // 不存在或者失效 1-用户在线 2-不可认证
    NSInteger state = [[[Authentication alloc] init] getUserTokenState];
    if (state==1) {
        // 已登录
        KZSetUserDefaults(@"1", KZOnlineKey);
//        [self getSystemIP];
//        [self getImgIP];
//        [self getTestLayerWithInfo:[[[Authentication alloc]init] userInfofromCheyChain]];
        
        KZTabBarController *vc = [KZTabBarController new];
        self.window.rootViewController = vc;
    } else {
        KZSetUserDefaults(@"1", KZOnlineKey);
        [self gotoLogin];
    }
}

#pragma mark - 启动登录界面
- (void)gotoLogin {
    Authentication *auth = [[Authentication alloc] init];
    [auth loginWithSystemID:@"101" titleName:@"英语智能备考" success:^{
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            //存储本次账号和地址
            NSString *addressString = [AddressOperater getBaseAddress];
            KZSetUserDefaults(addressString, KZMacAddressKey);
//            NSString *userID = DR_UserInfo.UserID;
//            KUserDefaults(userID, LG_Old_UserID);
            //本次登录成功
//            KUserDefaults(@"1", BKIsLogin);
            dispatch_async(dispatch_get_main_queue(), ^{
//                //在主线程中执行
//                [self getSystemIP];
//                [self getImgIP];
//                [self getTestLayerWithInfo:[[[Authentication alloc]init] userInfofromCheyChain]];
//
//                //LSHomeViewController *home = [[LSHomeViewController alloc] init];
//                LSNewHomeViewController *home = [[LSNewHomeViewController alloc] init];
//                UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:home];
//                self.window.rootViewController = navigationController;
                
            });
        });
    }];
}


#pragma mark - app status changed
- (void)applicationWillResignActive:(UIApplication *)application {
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
}
- (void)applicationWillTerminate:(UIApplication *)application {
}


@end
